package org.bonorsoft.modules.education.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.bonorsoft.modules.education.entity.Response;
import org.bonorsoft.modules.education.vo.ResponseVo;

import java.util.List;

/**
 * @Description: 通知回复表
 * @Author: WilliamYe
 * @Date: 2021-06-22
 * @Version: V1.0
 */
public interface ResponseMapper extends BaseMapper<Response> {

    /**
     * 根据通知id查询回复数量
     *
     * @param noticeId
     * @return
     */
    @Select("select count(0) from sys_response " +
            "where notice_id = #{noticeId} and response_sender = #{addresseeName} ")
    int countByNoticeId(String noticeId, String addresseeName);

    /**
     * 根据通知id获取所有回复
     *
     * @param noticeId
     * @return
     */
    @Select("select response_id, notice_id, response_sender, response_time, response_content, enclosure_name as file_name, enclosure_route as file_route " +
            "from sys_response, sys_enclosure " +
            "where notice_id = #{noticeId} and response_id = notice_response_id ")
    List<ResponseVo> getResponseByNoticeId(String noticeId);

    /**
     * 通过通知id和收件人获取所有回复
     * @param noticeId
     * @param addresseeName
     * @return
     */
    @Select("select response_id, notice_id, response_sender, response_time, response_content, enclosure_name as file_name, enclosure_route as file_route " +
            "from sys_response, sys_enclosure " +
            "where notice_id = #{noticeId} and response_sender = #{addresseeName} and response_id = notice_response_id ")
    List<ResponseVo> getResponseByNoticeIdAndName(String noticeId, String addresseeName);

    /**
     * 通过通知id删除所有回复
     * @param noticeId
     */
    @Delete("delete from sys_response " +
            "where notice_id = #{noticeId} ")
    void removeByNoticeId(String noticeId);


}
